package com.eonmind.pay.task;

import com.eonmind.common.provider.entity.pay.Order;
import com.eonmind.pay.service.OrderService;
import com.eonmind.pay.service.PayService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

/**
 * @ClassName WxPayScheduledTask
 * @Description TODO
 * Author 32004
 * Date 2025/6/4 21:14
 * Version 1.0
 **/

@Component
@Slf4j
public class WxPayScheduledTask {

    @Resource
    OrderService orderService;

    @Resource
    PayService payService;

    // 每30秒查询超过5分钟未支付的订单，并核实订单状态
    @Scheduled(cron = "0/30 * * * * ?" )
    public void orderConfirm() throws IOException {


        List<Order> orderInfoList = orderService.getNoPayByDuration(5);

        for(Order order : orderInfoList){
            log.warn("超时订单 ===> {}", order.getId());

            //核实订单状态，调用微信支付查单接口
            payService.checkOrderStatus(order.getId());
        }
    }


}
